//============================================================================
// Name        : dppmInstancesGenerator.cpp
// Author      : mattia
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include "signatures.h"
#include <iostream>
#include <stdlib.h>
#include <time.h>
#include <string.h>
#include <sstream>
using namespace std;

int main() {
	srand(time(NULL));

	int n, numInstances;
	float expected_cnc, expected_ci, theta;

	cout << "!!!Hello World!!!" << endl;

	cout << "N: ";
	cin >> n;

	cout << "Coefficient of Network Complexity (CNC) (CNC <= (n-1)/4): ";
	cin >> expected_cnc;

	cout << "Complexity Index (CI) (CI <= (n-3)): ";
	cin >> expected_ci;

	cout << "Theta: ";
	cin >> theta;

	cout << "Numero de instancias a generar con los parametros elegidos: ";
	cin >> numInstances;

	int numP[n];
	int * P[n];
	float cnc, ci;
	int M[n];
	int * times[n];
 	int * costs[n];
	int T;

	for(int i = 0; i < numInstances; i++){

		//Generar función predecesores
		if (generateDag3(n,expected_cnc,expected_ci,numP,P, cnc, ci)){

			cout << "Error definiendo predecesores en la generación de la "
				 << i << "-ésima instancia!!" << endl;

		}else{

			//Generar M, times y costs
			if (createModes(n,M,times,costs)){

				cout << "Error creando modos en la generación de la "
					 << i << "-ésima instancia!!" << endl;

			}else{

				//Generar deadline T
				if (defineDeadline(n,numP,P,M,times,theta,T)){

					cout << "Error generando el deadline de la "
						 << i << "-ésima instancia!!" << endl;

				}else{

					stringstream filename;
					filename << "DppmSpec_n-" << n << ",cnc-" << cnc
							<< ",ci-" << ci << ",theta-" <<theta << "_" << i<< ".dppm";

					//Escribir archivo
					if (writeFile(string(filename.str()).c_str(),n,T,numP,P,M,times,costs)){

						cout << "Error escribiendo el arhivo de la "
							 << i << "-ésima instancia!!" << endl;

					}

				}

				//Liberar memoria de times y costs
				for (int j = 0; j < n; j++){
					delete [] times[j];
					delete [] costs[j];
				}

			}

			//Liberar memoria de P
			for (int j = 0; j < n; j++){
				delete [] P[j];
			}

		}

	}

	return 0;
}
